﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mgh.Data.Sql;
using System.Data;

namespace A2Z.DataAccess
{
    public class BettingDA : Mgh.Data.Sql.ClassBase
    {
        protected BettingDA() { }

        private BettingDA(DataConnection cnn)
        {
            this.IConnection = cnn;
        }

        #region get

        protected dataSource.Fb_Vw_Betting_Match_ScoreDataTable _getFBettingByDate(string matchID, Int16 win)
        {
            bool isOpen = false;
            try
            {
                if (openConnect(ref isOpen))
                {
                    dataSource.Fb_Vw_Betting_Match_ScoreDataTable tb = new dataSource.Fb_Vw_Betting_Match_ScoreDataTable();
                    DataAdapter adap = new DataAdapter(IConnection, tb.TableName);
                    if (!string.IsNullOrEmpty(matchID))
                    {
                        adap.WhereText = tb.MatchIDColumn.ColumnName + "=@matchID and ";
                        adap.addParameter("matchID", SqlDbType.VarChar, matchID, ParameterDirection.Input);
                    }
                    if (win.Equals(1))
                    {
                        adap.WhereText = tb.CScoreAColumn.ColumnName + "=" + tb.ScoreAColumn.ColumnName + " and ";
                        adap.WhereText = tb.CScoreBColumn.ColumnName + "=" + tb.ScoreBColumn.ColumnName + " and ";
                    }
                    else if (win.Equals(2))
                    {
                        adap.WhereText = tb.CScoreAColumn.ColumnName + "!=" + tb.ScoreAColumn.ColumnName + " and ";
                        adap.WhereText = tb.CScoreBColumn.ColumnName + "!=" + tb.ScoreBColumn.ColumnName + " and ";
                    }

                    adap.WhereText = adap.WhereText.Trim().TrimEnd('a', 'n', 'd');
                    if (adap.fillData(tb))
                    {
                        return tb;
                    }
                    else addMessage(adap.getMsgCode(), adap.getMessage(), adap.getNumber());
                }
                else addMessage(IConnection.getMsgCode(), IConnection.getMessage(), IConnection.getNumber());
            }
            finally { closeConnect(isOpen); }
            return null;
        }

        #endregion

        #region insert

        protected bool _insertBettings(dataSource.Fb_Tbl_BettingDataTable tb)
        {
            bool isOpen = false;
            try
            {
                if (openConnect(ref isOpen))
                {
                    DataAdapter adap = new DataAdapter(IConnection, tb.TableName);
                    if (adap.addData(tb))
                    {
                        return true;
                    }
                    else addMessage(adap.getMsgCode(), adap.getMessage(), adap.getNumber());
                }
                else addMessage(IConnection.getMsgCode(), IConnection.getMessage(), IConnection.getNumber());
            }
            finally { closeConnect(isOpen); }
            return false;
        }

        protected bool _insertSBetting(dataSource.Fb_Tbl_Betting_ScoreDataTable tb)
        {
            bool isOpen = false;
            try
            {
                if (openConnect(ref isOpen))
                {
                    DataAdapter adap = new DataAdapter(IConnection, tb.TableName);
                    if (adap.addData(tb))
                    {
                        return true;
                    }
                    else addMessage(adap.getMsgCode(), adap.getMessage(), adap.getNumber());
                }
                else addMessage(IConnection.getMsgCode(), IConnection.getMessage(), IConnection.getNumber());
            }
            finally { closeConnect(isOpen); }
            return false;
        }

        #endregion

        #region update

        protected bool _updateBettings(dataSource.Fb_Tbl_BettingDataTable tb)
        {
            bool isOpen = false;
            try
            {
                if (openConnect(ref isOpen))
                {
                    DataAdapter adap = new DataAdapter(IConnection, tb.TableName);
                    if (adap.upData(tb))
                    {
                        return true;
                    }
                    else addMessage(adap.getMsgCode(), adap.getMessage(), adap.getNumber());
                }
                else addMessage(IConnection.getMsgCode(), IConnection.getMessage(), IConnection.getNumber());
            }
            finally { closeConnect(isOpen); }
            return false;
        }

        protected bool _updateSBettings(dataSource.Fb_Tbl_Betting_ScoreDataTable tb)
        {
            bool isOpen = false;
            try
            {
                if (openConnect(ref isOpen))
                {
                    DataAdapter adap = new DataAdapter(IConnection, tb.TableName);
                    if (adap.upData(tb))
                    {
                        return true;
                    }
                    else addMessage(adap.getMsgCode(), adap.getMessage(), adap.getNumber());
                }
                else addMessage(IConnection.getMsgCode(), IConnection.getMessage(), IConnection.getNumber());
            }
            finally { closeConnect(isOpen); }
            return false;
        }

        #endregion

        #region delete

        #endregion
    }
}
